package sk.tuke.constraintbuilder.views.components;

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.wb.swt.SWTResourceManager;

public abstract class ConstraintEditorDropAdapter extends DropTargetAdapter {
	
	@Override
	public abstract void drop(DropTargetEvent event);
	
	@Override
	public void dragEnter(DropTargetEvent event) {
		if (event.detail == DND.DROP_DEFAULT) {
			event.detail = (event.operations & DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;
	        DropTarget target = (DropTarget) event.widget;
		    target.getControl().setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
	    }
		// Allow dropping text only
	    for (int i = 0, n = event.dataTypes.length; i < n; i++) {
	    	if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
	    		event.currentDataType = event.dataTypes[i];
	        }
	    }
	}
	
	@Override
	public void dragLeave(DropTargetEvent event) {
		DropTarget target = (DropTarget) event.widget;
	    target.getControl().setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
	}
}
